package com.zj.base.list.adapters;

import android.support.annotation.IdRes;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.zj.base.list.holders.BaseViewHolder;

import java.util.List;

/**
 * Created by zhaojie on 2018/4/4.
 */

public abstract class BaseAdapter<T> extends BaseRecyclerAdapter<BaseViewHolder, T> {

    private final int resId;
    private LayoutInflater inflater;

    protected BaseAdapter(@IdRes int id) {
        resId = id;
    }

    protected BaseAdapter(@IdRes int id, List<T> datas) {
        resId = id;
        change(datas);
    }

    @Override
    public final BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (inflater == null) inflater = LayoutInflater.from(parent.getContext());
        return new BaseViewHolder(this, inflater.inflate(resId, parent, false));
    }

    @Override
    public final void onBindViewHolder(BaseViewHolder holder, int position) {
        initData(holder, position, getItem(position));
    }

    protected abstract void initData(BaseViewHolder holder, int position, T module);


}
